%% This script produces Figure 4 in Nucera, Sarno and Zinna "Currency Risk Premiums Redux", published on the RFS
lam_mf_vectmp  = mean(vhat); % annualized 
lam_mf_mattmp  = ones(size(betahat, 1), 1)*lam_mf_vectmp;
xr_2passtmp  = xper*cumsum(lam_mf_mattmp.*betahat, 2);
xr_2obstmp   = xper*xm2y*repmat(nanmean(R(2:end, :), 1)', 1, pmax);

nnmod    = 1;
jpcvec   = [2 3];
nC       = length(jpcvec);
nR       = length(nnmod);
iplottmp = 0;

tittxt = strvcat(strcat('$\varphi(F(1-2)), \omega=$', num2str(w)),...
                 strcat('$\varphi(F(1-3)), \omega=$', num2str(w)));

figure('Name', 'Fig4') 
for jpc = jpcvec
for nmodloop = nnmod
    
iplottmp = 1 + iplottmp;    
    
legtxt = strvcat(' ');
wmark = 100;
wlab  = 12;
wtit  = 16;
wax   = 12;
wleg  = 10;
wmleg = 12;


dataploty = xr_2obstmp(:, jpc, nmodloop);
dataplotx = xr_2passtmp(:, jpc, nmodloop);
regrR2=corr(dataplotx,dataploty)^2; 
dataplot=[dataploty' dataplotx'];

NP1=2;
NP2=3;

carry   = repmat([1 1 1], NP, 1);
momst   = repmat([2 2 2], NP, 1);
momlt   = repmat([3 3 3], NP, 1);
value   = repmat([4 4 4], NP, 1);
nfa     = repmat([5 5 5], NP, 1);
ldc     = repmat([6 6 6], NP1*NP2, 1);
term    = repmat([7 7 7], NP, 1);
yld     = repmat([8 8 8], NP, 1);
gap     = repmat([9 9 9], NP, 1);

group = [carry; momst; momlt; value; nfa; ldc; term; yld; gap;];

subplot(nC, nR, iplottmp)
gscatter(dataplotx,dataploty,group,'kkkkkkk','+o*xsd^v<',10);
xlim([-2 8])
ylim([-2 8])
hline = refline(1,0);
hline.Color = 'k'; 
c = cellstr(MatPrtLab);
dx = 0.05; dy = 0.05; % displacement so the text does not overlay the data points
htit  = title(tittxt(iplottmp, :),'Interpreter','Latex');    
set(htit,'FontSize',wtit,'fontweight','normal','fontname','Bookman Old Style')
xlab=xlabel('Model $\overline{X}$ (p.a.)','Interpreter','Latex');
set(xlab,'FontSize',wlab,'FontWeight','normal','fontname','Bookman Old Style')
ylab=ylabel('Observed $\overline{X}$ (p.a.)','Interpreter','Latex');
set(ylab,'FontSize',wlab,'FontWeight','normal','fontname','Bookman Old Style')
leg =legend('Carry', 'Mom (ST)', 'Mom (LT)', 'NFA', 'LDC', 'Value', 'Term', 'LYld', 'GAP'); 
legend boxoff
set(leg, 'FontSize',wleg,'fontname','Bookman Old Style');
set(gca,'FontSize',wax);
set(gca,'fontname','Bookman Old Style');
grid on
box on

end    
end